<?php
/**
 * 消息管理
 */
namespace app\modules\user\controllers;

use app\modules\user\models\MockUser;
use app\modules\user\models\News;
use app\modules\user\models\User;
use yii;
use app\libs\ApiControl;
use app\libs\Method;

class MockUserController extends ApiControl
{
    public $enableCsrfValidation = false;
    public $layout = 'user';

    /**
     * [actionIndex 系统消息列表]
     * @Author yoyo
     * @Date   2023-04-28
     */
    public function actionIndex()
    {
        $page = Yii::$app->request->get('page', 1);
        $beginTime = strtotime(Yii::$app->request->get('beginTime', ''));
        $endTime = strtotime(Yii::$app->request->get('endTime', ''));
        $phone = Yii::$app->request->get('phone', '');
        $wx = Yii::$app->request->get('wx', '');
        $id = Yii::$app->request->get('id', '');
        $where = "1=1";
        if ($beginTime) {
            $where .= " AND mi.createTime>=$beginTime";
        }
        if ($endTime) {
            $endTime += 86400;
            $where .= " AND mi.createTime<=$endTime";
        }
        if ($id) {
            $where .= " AND mi.id = $id";
        }
        if ($wx) {
            $where .= " AND wx = '$wx'";
        }
        if ($phone) {
            $where .= " AND mi.phone = '$phone'";
        }

        $model = new MockUser();
        $data = $model->getMockUser($where, $pageSize = 10, $page);
        $page = Method::getPagedRows(['count' => $data['count'], 'pageSize' => 10, 'rows' => 'models']);
        return $this->render('index', ['page' => $page, 'data' => $data['data']]);
    }

    /**
     * 联系客户
     * @Author: yoyo
     * @create: 2023/3/15 16:47
     */
    public function actionHandleStatus()
    {
        $id = Yii::$app->request->get('id');
        $re=MockUser::updateAll(['status' => 1], "id =$id");
        if($re){
            die('<script>alert("修改成功");history.go(-1);</script>');
        }
    }


}